package com.persistence;

import java.util.ArrayList;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

public abstract class DataAccessObject<T> {
	private static final PersistenceManagerFactory pmfInstance =
			JDOHelper.getPersistenceManagerFactory("transactions-optional");
	protected PersistenceManager persistenceManager;
	
	public void insertObject(T insertingObject){
		getPersistenceManagerInstance();
		insertData(insertingObject);
		closePersistenceManager();
	}
	
	public abstract ArrayList<T> getObjects();
	public abstract T getObject(String searchValue);
	private void insertData(T inInsertingData){
		persistenceManager.makePersistent(inInsertingData);
	}
	
	protected void getPersistenceManagerInstance(){
		persistenceManager = pmfInstance.getPersistenceManager();
	}
	
	protected void closePersistenceManager(){
		persistenceManager.close();
	}
}
